/*
  对象深拷贝
*/
// var obj1 = { a: 1, b: { a: 1, b: 'hh' }, c: [1, 2, 3] }
// var a1 = obj1;
// console.log(a1);
// console.log(obj1);
// a1.a = 3
// console.log(a1);
// console.log(obj1);
// var test1 = 'a';
// console.log('----------------------------------');

// function deepclone(old) {
//   var newobj;
//   old instanceof Object ? (old instanceof Array ? newobj = [] : newobj = {}) : newobj = old;
//   if (old instanceof Array) {
//     for (var i = 0; i < old.length; i++) {
//       newobj.push(old[i]);
//     }
//   } else if (old instanceof Object) {
//     for (var item in old) {
//       console.log(old[item]);
//       newobj[item] = deepclone(old[item]);
//     }
//   }
//   return newobj;
// }
// var b = deepclone(obj1);
// obj1.b.a = 2
// obj1.a = 2
// obj1.c[1] = 11
// console.log('----------------------------------');
// console.log(b);
// console.log(obj1);
// console.log('----------------------------------');
// console.log('obj1.b(对象) instanceof Array结果为' + (obj1.b instanceof Array));
// console.log('obj1.b(对象) instanceof Object结果为' + (obj1.b instanceof Object));
// console.log('obj1.c(数组) instanceof Array结果为' + (obj1.c instanceof Array));
// console.log('obj1.c(数组) instanceof Object结果为' + (obj1.c instanceof Object));
// console.log('----------------------------------');

// var c = ['asda', 1, 23, { a: 1, b: { cc: [1, 2, 3], aa: 'asa' } }, [1, 2, 3]]
// var d = deepclone(c);
// c[1] = 100;
// console.log(c);
// console.log(d);

/*
数组扁平化去重升序处理
*/
const arr1 = [100, 21, 23, [11, 45, [22, 5], 10], 10, [22, 56, 213, 45], 33, 22, 11];
function flatorderset(arr) {
  const newarr = [];
  function flat(arr, newarr) {
    for (item of arr) {
      if (item instanceof Array) {
        flat(item, newarr)
      } else {
        newarr.push(item);
      }
    }
  }
  flat(arr, newarr);
  const newarr1 = [...new Set(newarr)]

  for (let i = 0; i < newarr1.length; i++) {
    for (let j = 0; j < newarr1.length - i - 1; j++) {
      if (newarr1[j] > newarr1[j + 1]) {
        newarr1[j + 1] = newarr1[j] + newarr1[j + 1];
        newarr1[j] = newarr1[j + 1] - newarr1[j];
        newarr1[j + 1] = newarr1[j + 1] - newarr1[j];
      }
    }
  }
  return newarr1;
}

const arr2 = flatorderset(arr1);
console.log(arr2);